Skip to content

Emit named GraphQL operations for generated tools#891

Open
oscnord wants to merge 1 commit into
RhysSullivan:mainfrom
oscnord:feat/named-graphql-operations
Open

Emit named GraphQL operations for generated tools#891
oscnord wants to merge 1 commit into
RhysSullivan:mainfrom
oscnord:feat/named-graphql-operations

Conversation

@oscnord
Copy link
Copy Markdown

@oscnord oscnord commented Jun 4, 2026

Problem

Generated GraphQL operations are anonymous — e.g. query($slug: ID!) { contentcollection(slug: $slug) { ... } }. Two consequences:

  • Servers that require named operations reject every invocation. (Apollo Server can be configured this way; some gateways enforce it unconditionally and return a 400 before the resolver runs.)
  • APM/observability tooling (Apollo Studio, New Relic, Datadog) keys traces and transaction names off the operation name, so all anonymous operations collapse into a single unnamed bucket.

Change

Derive an operation name from the root field and emit it in the generated document, so contentcollection produces:

query Contentcollection($slug: ID!) { contentcollection(slug: $slug) { ... } }
  • buildOperationStringForField and the anonymous fallback path both name the operation.
  • The name is the root field name with its first character upper-cased; GraphQL field names are already valid name tokens, so no further escaping is needed.
  • Each generated document contains exactly one operation, so there is no naming-collision concern.
  • The request body is unchanged otherwise; servers derive operationName from the document, so no separate operationName field is required.

Tests

Added a test asserting a query and a mutation are sent as named operations (query Hello …, mutation SetGreeting …). Full @executor-js/plugin-graphql suite passes; typecheck, oxfmt, and oxlint are clean.

@oscnord oscnord force-pushed the feat/named-graphql-operations branch from 6a0f85b to 3c7d2a3 Compare June 4, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant